<template>
  <div>
    <pre v-html="data"></pre>
    <el-row v-if="$store.state.edit.row.level != 1">
      <el-col :span="5">
        <el-button size="mini" type="primary" @click="createToken">生成客户token</el-button>
        <div style="color: darkred">(新增不用点击)</div>
      </el-col>
      <el-col :span="15">
        <div class="grid-content bg-purple">
          <el-input size="mini" v-model="id" value="$store.state.edit.row.customerToken"></el-input>
        </div>
      </el-col>
    </el-row>
    <!--<el-input v-model="id" value="$store.state.edit.row.id" type="hidden"></el-input>-->
  </div>
</template>

<script>
import { ajax } from "@/store/yg/common/utils";

export default {
  props: ["data"],
  data() {
    return {
      id: ""
    };
  },
  methods: {
    createToken() {
      var id= this.$store.state.edit.row["id"];
      if (typeof id === "undefined"){
        this.$message.error('生成鉴权失败,ID为空!');
        return;
      }
      var data = {};
      data["id"] = id;
      ajax("createCustomerToken", data).then(
        res => {
          if (res.code===200){
            this.id = res.message;
            this.$message.success('生成鉴权token成功!');
            return;
          }else{
            this.$message.error('生成鉴权token失败!');
            return;
          }
        },
        error => {
          console.log(error);
        }
      );
    }
  }
};
</script>
